const api = require('../../api/api.js');
const app = getApp();

Page({
  data: {
    imgUrl: app.globalData.imgUrl + 'placeImage/',
    places: []
  },
  onLoad() {
    let that = this;
    let imgUrl = that.data.imgUrl;
    wx.getStorage({
      key: 'userId',
      success(res) {
        let userId = res.data;
        api.userGetClaim({
          data: {
            account: userId
          },
          success(res) {
            console.log(res.data);
            let dataArr = []
            let places = res.data.places
            let plantations = res.data.plantations
            let enterprises = res.data.enterprises
            for(let i = 0; i < places.length; i++) {
              dataArr.push({
                entName: enterprises[i].entName,
                entId: enterprises[i].entId,
                siteName: plantations[i].siteName,
                siteId: plantations[i].siteId,
                placeName: places[i].placeName,
                placeId: places[i].placeId
              })
            }
            that.setData({
              places: dataArr
            });
          }
        });
      }
    })
  },
  goToPlacePage(e) {
    let data = e.currentTarget.dataset
    let entId = data.entid
    let siteId = data.siteid
    let placeId = data.placeid
    wx.navigateTo({
      url: `/pages/place/place?placeId=${placeId}&siteId=${siteId}&entId=${entId}`,
    })
  }
})